const path = require("path");
const fs = require("fs");
const wiriteToFile = async (pathname, content) => {
  // let lastIndexOf = path.lastIndexOf('\\')
  // let dir = path.substring(0,lastIndexOf)
  let dir = path.dirname(pathname);
  return fs.promises.mkdir(dir, { recursive: true }).then(
    () => {
      return fs.promises.writeFile(pathname, content);
    },
    () => {
      console.err("创建路径：" + dir + "失败！");
      return fs.promises.writeFile(pathname, content);
    }
  );
};
module.exports = { wiriteToFile };
